<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>汽车衡称重系统</title>
	<link href="__STATIC__/css/common.css" rel="stylesheet">
	<link rel="stylesheet" href="__STATIC__/css/index.css">
	<link rel="stylesheet" type="text/css" href="__STATIC__/js/datetimepicker/jquery.datetimepicker.css"/>
	<style>
		.ms-controller{
			display:none;
		}
	</style>
</head>
<body ms-controller="view" class="ms-controller" ms-visible="display_main">
	<div class="header" style="display:none;">
		<div class="header-box">
			<ul class="menu-box">
				<li class="menu-item" ms-class="menu-active:menu_label == 'scale'" ms-click="changeMenu('scale')">称重</li>
				<li class="menu-item" ms-class="menu-active:menu_label == 'system'" ms-click="changeMenu('system')">系统维护</li>
				<li class="menu-item" ms-class="menu-active:menu_label == 'report'" ms-click="changeMenu('report')">统计报表</li>
				<li class="menu-item" ms-class="menu-active:menu_label == 'function'" ms-click="changeMenu('function')">财务核算</li>
				<li class="menu-item"><a style="color:blue;" target="_blank" href="/home/index/insertByHand">手动补单</a></li>
			</ul>
		</div>
	</div>

	<div class="main">
		<h2 style="width:100%;text-align:center;height:40px;line-height:40px;">手工补单</h2>
		<div class="insert-box">
			<div class="insert-left">
				<p class="insert-text">请点击右侧的下载表格按钮,下载一个空白表格,然后按照表格中的示范内容认真填写磅单并保存.然后在点击右侧的上传按钮,把填写好的表格上传到服务器中,系统会自动把表格中的数据保存在数据库中.</p>
			</div>
			<div class="insert-right">
				<a class="insert-btn" style="text-align:center;" href="/public/upload/template.xlsx">下载表格</a>
				<button class="insert-btn" ms-click="toUpload">上传数据</button>
			</div>
		</div>
		<h2 style="width:100%;text-align:center;margin-top:10px;">导入成功列表</h2>
		<div class="data-box">
			<table class="weigh_list" border="1" cellspacing="0" ms-visible="success_list.length > 0" style="font-size:14px;table-layout:fixed">
				<tr>
					<th>编号</th>
					<th>磅单编号</th>
					<th>过磅日期</th>
					<th>物资名称</th>
					<th>车牌号码</th>
					<th>司机姓名</th>
					<th>皮&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重</th>
					<th>检皮时间</th>
					<th>检皮人员</th>
					<th>毛&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重</th>
					<th>检重时间</th>
					<th>检重人员</th>
					<th>净&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;重</th>
					<th>发货单位</th>
					<th>收货单位</th>
					<th>发货位置</th>
					<th>发运路线</th>
					<th>钩机号</th>
					<th>磅房名称</th>
				</tr>
				<tr ms-repeat-el='success_list'>
					<td ms-text="$index + 1"></td>
					<td ms-text="el.billCode"></td>
					<td ms-text="el.billDateDesc"></td>
					<td ms-text="el.goodsName"></td>
					<td ms-text="el.truckCode"></td>
					<td ms-text="el.driver"></td>
					<td ms-text="el.emptyWeigh"></td>
					<td ms-text="el.emptyTimeDesc"></td>
					<td ms-text="el.emptyOperator"></td>
					<td ms-text="el.fullWeigh"></td>
					<td ms-text="el.fullTimeDesc"></td>
					<td ms-text="el.fullOperator"></td>
					<td ms-text="el.weigh"></td>
					<td ms-text="el.sendUnit"></td>
					<td ms-text="el.receiveUnit"></td>
					<td ms-text="el.position"></td>
					<td ms-text="el.route"></td>
					<td ms-text="el.excavator"></td>
					<td ms-text="el.houseName"></td>
				</tr>
			</table>
		</div>
		<h2 style="width:100%;text-align:center;margin-top:10px;">导入失败列表</h2>
		<div class="data-box">
			<table class="weigh_list" border="1" cellspacing="0" ms-visible="fail_list.length > 0" style="font-size:14px;table-layout:fixed">
				<tr>
					<th>编号</th>
					<th>错误代码</th>
				</tr>
				<tr ms-repeat-el="fail_list">
					<td ms-text="$index + 1"></td>
					<td ms-text="el"></td>
				</tr>
			</table>
		</div>
		<input type="file" name="" id="files1" style="display:none;">
	</div>
	<script src="__STATIC__/js/jquery.min.js"></script>
	<script src="__STATIC__/js/layer/layer.js"></script>
	<script src="__STATIC__/js/avalon.js"></script>
	<script src="__STATIC__/js/common.js"></script>
	<script src="__STATIC__/js/jquery.cookie.min.js"></script>
	<script src="__STATIC__/js/logic.js"></script>
	<script src="__STATIC__/js/validator.js"></script>
	<script src="__STATIC__/js/ajaxfileupload.js"></script>
	

	<script>
	jQuery(document).ready(function(){
		avalon.config({
          interpolate : ["(|","|)"]
        });
        $("#weigh_list").bind("contextmenu", function(){return false;});
        $("#rightMenu").bind("contextmenu", function(){return false;});
		var Tcom = null;
		var w = $(document).width();
		var h = $(document).height();
		Array.prototype.in_array=function(e){
			var r=new RegExp(','+e+',');  
			return (r.test(','+this.join(this.S)+','));  
		};
		
		var vm = avalon.define({
        	$id : "view",
        	houseId:0,
        	houseName:'',
        	user_info:{},
        	user_list:[],
        	user_power:[],
        	house_list:[],
        	config:{weighModel:0,codeType:0,codeLen:3,codePagearea:'',codePrintarea:''},        	
        	display_main:true,
        	success_list:[],
        	fail_list:[],
        	filename:'',
        	menu_label:'',
        	load:function(){
        		$.post(logic_urls.index,{},
        			function(data,textStatus){
        				var json = TX.toJson(data);
        				console.log(json.data);
        				var t = Date.parse(new Date()) / 1000;
        				if(Math.abs(t - json.time) >= 3000){
        					var tt = new Date(parseInt(json.time) * 1000).toLocaleString();
        					alert('当前系统与服务器时间不同步,服务器时间为:' + tt + ".请手动修改系统时间",{icon:3,skin: 'layer-ext-moon'});
        					vm.display_main = false;
        					return;
        				}
        				for(var k in json.data){
        					vm[k] = json.data[k];
        				}
        				vm.user_power = vm.user_info.power.split(',');
        				var vx = vm.user_power.in_array('accounting');
        				if(!vx && vm.user_info.isManager != 1){
        					vm.display_main = false;
        					alert('您没有权限访问本页面',{icon:3,skin: 'layer-ext-moon'});
        				}
        				avalon.scan();
        			}
        		);
        	},
        	toUpload:function(){
        		$("#files1").click();
        	},
        });
		vm.load();
		$("#files1").change(function(e){
			var f = new FormData();
			f.append('file',this.files[0]);
			console.log(f);
			$.ajax({
				url:'/home/apps/insertByHand?houseId=1',
				type: 'POST',
				cache: false,
				data: f,
				processData: false,
				contentType: false,
				success:function(data){
					var json = TX.toJson(data);
					console.log(json);
					if(json.status == 1){
						TX.msg('手工补单成功',{time:3000,icon:3,skin: 'layer-ext-moon'});
						vm.success_list = json.data;
						vm.fail_list = json.err;
						avalon.scan();
					}else if(json.status == -2){
						TX.msg('手工补单失败,代码为:' + json.msg,{time:3000,icon:3,skin: 'layer-ext-moon'});
					}else{
						TX.msg('手工补单失败,代码为' + json.msg,{time:3000,icon:3,skin: 'layer-ext-moon'});
						vm.success_list = json.data;
						vm.fail_list = json.err;
						avalon.scan();
					}
				},
				complete(XHR, TS){
					console.log(XHR);
					console.log(TS);
				}
			});
		});
	});
	</script>
</body>
</html>